package com.twu.biblioteca;

import java.util.Arrays;
import java.util.Scanner;

/**
 * Created by dmortime on 11/03/2014.
 */
public class BibliotecaApp {

    private void go(OutputWriter outputWriter, InputReader inputReader, Library library, Customer customer) {
        IMenu menu = new MainMenuWithLoggedInCustomer(outputWriter, inputReader, library, customer);
        while(menu != null) {
            menu.display();
            menu = menu.nextMenu();
        }
    }

    static public void main(String[] args) {
        OutputWriter outputWriter = new ConsoleOutputWriter();
        InputReader inputReader = new ConsoleInputReader();
        Library library = new Library();
        library.addBooks(
                new Book("Farenheit 451"),
                new Book("Homage to Catalonia"),
                new Book("Small is Beautiful"),
                new Book("The Lorax")
        );
        Customer customer = new Customer("111-1111", "password");

        BibliotecaApp app = new BibliotecaApp();

        app.go(outputWriter, inputReader, library, customer);
    }
}

class ConsoleOutputWriter implements OutputWriter {
    @Override
    public void writeLines(String... lines) {
        for(String line : Arrays.asList(lines)) {
            System.out.println(line);
        }
    }
}

class ConsoleInputReader implements InputReader {
    private Scanner scanner;
    ConsoleInputReader () {
        scanner = new Scanner(System.in);
    }

    @Override
    public String getInput() {
        return scanner.nextLine();
    }
}